<?php
/**
 * Created by PhpStorm.
 * User: s7175
 * Date: 2019/8/19
 * Time: 21:03
 */

namespace App\Http\Utils;


use Casbin\Enforcer;
use Casbin\Exceptions\CasbinException;
use mysql_xdevapi\Exception;

class Casbin
{

    private $casbin = null;

    public function __construct()
    {
        if (empty($this->casbin)) {
            $path = app()->resourcePath('admin');
            try {
                $a = DatabaseAdapter::newAdapter([
                    'type' => 'mysql', // mysql,pgsql,sqlite,sqlsrv
                    'hostname' => env('DB_HOST'),
                    'database' =>env('DB_DATABASE'),
                    'username' =>env('DB_USERNAME'),
                    'password' => env('DB_PASSWORD'),
                    'hostport' =>env('DB_PORT'),
                ]);
                $this->casbin = new Enforcer($path . DIRECTORY_SEPARATOR . 'rbac_model.conf', $a);
            } catch (CasbinException $exception) {
                dd($exception);
            }
        }
    }

    /**
     * 添加角色
     */
    public function addRole()
    {


    }

    /**
     * 添加组
     */

    public function addPolicy()
    {

    }
}